package com.yanqu.road.server.cmd.fellingtrees;

import com.yanqu.road.entity.activity.fellingtrees.FellingTreesUserData;
import com.yanqu.road.entity.activity.fellingtrees.config.FellingTreesConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.FellingTreesProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.fellingtrees.FellingTreesModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.fellingtrees.FellingTreesMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_FELLING_TREES_EQUIP_SETTING, desc = "")
public class FellingTreesEuipSettingCmd extends AbstractCommand {

    private FellingTreesProto.FellingTreesSettingMsg settingMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        FellingTreesProto.FellingTreesSettingReqMsg reqMsg = FellingTreesProto.FellingTreesSettingReqMsg.parseFrom(packet.getBytes());
        settingMsg = reqMsg.getSetting();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        FellingTreesConfig config = FellingTreesMgr.getFellingTreesConfig();
        if (config == null || !ActivityMgr.activityInTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_HAD_END;
            return;
        }
        FellingTreesUserData userData = player.getModule(FellingTreesModule.class).getUserData();
        if (userData == null) {
            ret = GameErrorCode.E_FELLING_TREES_NO_UNLOCK;
            return;
        }
        ret = GameErrorCode.E_FELLING_TREES_PARAM_ERROR; // 这个功能不要了
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            FellingTreesProto.FellingTreesSettingRespMsg.Builder builder = FellingTreesProto.FellingTreesSettingRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_FELLING_TREES_EQUIP_SETTING, builder);
        }
    }
}
